9 inline string
intToStr(const int &n
){stringstream ss
; ss
<<n
; string s
; ss
>>s
; return s
; }
10 inline int strToInt(const string
&n
){stringstream ss
; ss
<<n
; int s
; ss
>>s
; return s
; }
16 vector
<bool> forbidden(10000, false);
17 vector
<bool> visited(10000, false);
21 for (int i
=0; i
<4; ++i
){
22 int x
; scanf("%d", &x
);
23 start
= (start
* 10) + x
;
27 for (int i
=0; i
<4; ++i
){
28 int x
; scanf("%d", &x
);
36 for (int i
=0; i
<4; ++i
){
37 int x
; scanf("%d", &x
);
43 queue
<pair
<int, int> > q
;
45 q
.push(make_pair(start
, 0));
47 int node
= q
.front().first
;
48 int dist
= q
.front().second
;
58 for (int i
=0; i
<4; ++i
){
69 digit
= '0' + ((digit
- '0' + 1) % 10);
71 //cout << "t es: " << t << endl;
72 //cout << "neighbour es: " << strToInt(t) << endl;
73 neighbour
= strToInt(t
);
74 if (!forbidden
[neighbour
]){
75 q
.push(make_pair(neighbour
, dist
+ 1));
76 //cout << "Empuje " << q.front().first << endl;
81 digit
= '0' + ((digit
- '0' + 9) % 10);
83 neighbour
= strToInt(t
);
84 //cout << "neighbour es: " << strToInt(t) << endl;
85 if (!forbidden
[neighbour
]){
86 q
.push(make_pair(neighbour
, dist
+ 1));
87 //cout << "Empuje " << q.front().first << endl;
91 cout
<< answer
<< endl
;